using System;
using System.Collections.Generic;
using System.Reflection;
using Voodoo.Sauce.Core;
using Voodoo.Sauce.Internal;

namespace Voodoo.Sauce.Debugger
{
	public class VoodooSettingsDebugScreen : Screen
	{
		private readonly HashSet<string> _ignoreKeySet = new HashSet<string>
		{
			"NAME", "AccessTokenID", "AccessBundleID", "LastUpdateDate", "EnableInEditorUnityAds", "EnableInEditorRVAds", "EnableInEditorFSAds", "MaxPercentOfTotalIosCohorts", "MixpanelUsersPercentPerCohort", "RunningIosABTests",
			"CustomIosABTestsCountryCodes", "DebugForcedCohort", "EnableAndroidABTests", "EnableCustomAndroidABTestsCountryCodes", "MaxPercentOfTotalAndroidCohorts", "AndroidUsersPercentPerCohort", "RunningAndroidABTests", "CustomAndroidABTestsCountryCodes", "DebugAndroidForcedCohort", "NoAdsBundleId",
			"Products", "StudioLogoForSplashScreen", "GdprPrimaryColor", "VoodooLogLevelInEditor", "CrossPromo", "EditorIdfa", "IgnoreTheGoogleKeyError"
		};

		private void Awake()
		{
			DisplayVoodooSettingKeys();
		}

		private void DisplayVoodooSettingKeys()
		{
			Type typeFromHandle = typeof(VoodooSettings);
			VoodooSettings voodooSettings = VoodooSettings.Load();
			VoodooLog.LogDebug(Voodoo.Sauce.Internal.Module.ADS, "VoodooSauceSettingsKeys", $"Are VoodooSettings null: {voodooSettings == null}");
			FieldInfo[] fields = typeFromHandle.GetFields();
			VoodooLog.LogDebug(Voodoo.Sauce.Internal.Module.ADS, "VoodooSauceSettingsKeys", $"fields count: {fields.Length}");
			VoodooLog.LogDebug(Voodoo.Sauce.Internal.Module.ADS, "VoodooSauceSettingsKeys", string.Format("MaxAdsIosAdsKeys: {0}", typeFromHandle.GetField("MaxAdsIosAdsKeys").GetValue(voodooSettings)));
			VoodooLog.LogDebug(Voodoo.Sauce.Internal.Module.ADS, "VoodooSauceSettingsKeys", string.Format("MaxAdsAndroidAdsKeys: {0}", typeFromHandle.GetField("MaxAdsAndroidAdsKeys").GetValue(voodooSettings)));
			List<FieldInfo> list = new List<FieldInfo>(fields);
			list.Sort((FieldInfo a, FieldInfo b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));
			foreach (FieldInfo item in list)
			{
				string text = item.Name;
				if (!_ignoreKeySet.Contains(text) && !VoodooSettings.IsAdUnitFieldName(text))
				{
					CopyToClipboard(text, typeFromHandle.GetField(text).GetValue(voodooSettings)?.ToString());
				}
			}
		}
	}
}
